﻿$resultFilePath =  "C:\Users\LQ\Desktop\result.txt "
#Remove-Item $filePath

$content = Get-Content "C:\Users\LQ\Desktop\d.txt" ;

$lst = $content;#.Split([System.Environment]::NewLine,[StringSplitOptions]::RemoveEmptyEntries);

$outputString = "";

for ($i = 0; $i -lt $lst.Count; $i++)
{ 
        $item =  $lst[$i];
        $firstpointIndex =$item.IndexOf('"');
        $secondpointIndex =$item.LastIndexOf('"');
        $set_index_tail = $item.IndexOf("set")+3; #set字符在整个字符中的索引位置; t后面的那个索引号
        $leftquoto_index = $item.IndexOf("("); #左括号的索引位置
                
        $fieldName_self = $item.Substring($set_index_tail,$leftquoto_index-$set_index_tail);
        $fieldName_target = $item.Substring($firstpointIndex+1,$secondpointIndex-$firstpointIndex-1);
        $fieldName_target

        $diff = $secondpointIndex - $firstpointIndex;
        $itemVal = "";
        $fieldName = "";
        if ($diff  -eq 1)
        {
                $itemVal = 'StringUtil.removeNull("")';
        }
else
{
        $itemVal =[String]::Format('StringUtil.removeNull(lst.get(0).get("{1}"))','0',$fieldName_target) ;
}
              
$outputString += [String]::Format('QLF_QL_JSYDSYQ_Element.addAttribute("{0}",{1});',$fieldName_self,$itemVal)+[System.Environment]::NewLine;
}

$outputString >> $resultFilePath